using System.Data;
using Dapper.Abstractions;
using Microsoft.Data.SqlClient;

namespace Dapper.SqlServer;

public class SqlServerConnectionFactory : IDbConnectionFactory
{
    private readonly string _connectionString;

    public SqlServerConnectionFactory(string connectionString)
    {
        _connectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
    }

    public IDbConnection CreateConnection()
    {
        return new SqlConnection(_connectionString);
    }

    public Task<IDbConnection> CreateConnectionAsync()
    {
        return Task.FromResult<IDbConnection>(new SqlConnection(_connectionString));
    }
}
